﻿724.寻找数组的中心下标
int pivotIndex(int* nums, int numsSize) {
    int sum1 = 0, sum2 = 0, ans = 0;
    for (int i = 1; i < numsSize; i++)
    {
        sum2 += nums[i];
    }
    if (sum1 == sum2)
    {
        return 0;
    }

    for (int i = 0; i < numsSize - 1; i++)
    {
        sum1 += nums[i];
        sum2 -= nums[i + 1];
        if (sum1 == sum2)
        {
            ans = i + 1;
            break;
        }
        else
        {
            ans = -1;
        }
    }
    return ans;
}

645.错误的集合
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findErrorNums(int* nums, int numsSize, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * numsSize);
    int* arr = (int*)calloc(sizeof(int), numsSize);
    *returnSize = 0;

    for (int i = 0; i < numsSize; i++)
    {
        arr[nums[i] - 1]++;
        if (arr[nums[i] - 1] == 2)
        {
            ans[(*returnSize)++] = nums[i];
        }
    }

    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < numsSize; i++)
    {
        sum1 += (i + 1);
        sum2 += nums[i];
    }
    ans[(*returnSize)++] = sum1 - sum2 + ans[0];
    return ans;
}

657.机器人能否返回原点
bool judgeCircle(char* moves) {
    int hor = 0, ver = 0;
    while (*moves != '\0')
    {
        if (*moves == 'L')
        {
            hor++;
        }
        else if (*moves == 'R')
        {
            hor--;
        }
        else if (*moves == 'U')
        {
            ver++;
        }
        else
        {
            ver--;
        }
        moves++;
    }
    if (!hor && !ver)
    {
        return true;
    }
    else
    {
        return false;
    }
}